//
//  WHSearchResultController.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/14.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHSearchResultController.h"
#import "WHExpressResultCell.h"
#import "WHSearchDetailResultController.h"

@interface WHSearchResultController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *dataTableView;


@end

@implementation WHSearchResultController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"查询结果";
    [self setUpTableView];
}

- (void)setUpTableView {
    UITableView *dataTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    dataTableView.delegate = self;
    dataTableView.dataSource = self;
    [self.view addSubview:dataTableView];
    
    [dataTableView registerClass:[WHExpressResultCell class] forCellReuseIdentifier:NSStringFromClass([WHExpressResultCell class])];
    
    dataTableView.tableFooterView = [UIView new];
    dataTableView.backgroundColor = KClearColor;
    dataTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [dataTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.view);
        make.top.equalTo(@kTopHeight);
    }];
    
    _dataTableView = dataTableView;
}

#pragma mark - —————— UITableViewDelegate & UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.result.Shippers.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WHExpressResultCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([WHExpressResultCell class]) forIndexPath:indexPath];
    WHExpressNameArray *nameArray = self.result.Shippers[indexPath.section];
    cell.tipsLabel.text = nameArray.ShipperName;
    cell.desLabel.text = self.result.LogisticCode;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    WHExpressNameArray *nameArray = self.result.Shippers[indexPath.section];
    WHSearchDetailResultController *detail = [[WHSearchDetailResultController alloc] init];
    detail.waybillNum = self.result.LogisticCode;
    detail.expressCompany = nameArray.ShipperName;
    [self.navigationController pushViewController:detail animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kRealwidth(75);
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return kRealwidth(12);
}

@end
